﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using Be;

namespace Bll {

    /// <summary>
    /// The BllBookingService is the service class
    /// of BllBooking
    /// </summary>
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class BllBookingService : IBookingService {

        /// <summary>
        /// The object of the BllBooking class
        /// </summary>
        private readonly BllBooking _booking;

        /// <summary>
        /// Constructs the object
        /// </summary>
        public BllBookingService() {
            _booking = new BllBooking();
        }

        /// <summary>
        /// Get all bookings
        /// </summary>
        /// <returns>All bookings</returns>
        public List<BeBooking> GetBookings() {
            try {
                return _booking.GetBookings();
            } catch(Exception ex) {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// Get a booking from an id
        /// </summary>
        /// <param name="id">The id to get the booking from</param>
        /// <returns>The booking</returns>
        public BeBooking GetBookingFromId(int id) {
            try {
                return _booking.GetBookingFromId(id);
            } catch(Exception ex) {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// Get all bookings on a lesson
        /// </summary>
        /// <param name="lesson">The lesson to get the bookings from</param>
        /// <returns>The bookings</returns>
        public List<BeBooking> GetBookingsOnLesson(BeLesson lesson) {
            try {
                return _booking.GetBookingsOnLesson(lesson);
            } catch(Exception ex) {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// Get all bookings i a specific week
        /// </summary>
        /// <param name="starttimes">The start day</param>
        /// <param name="days">The days from starttimes</param>
        /// <returns>The bookings</returns>
        public List<BeBooking> GetBookingsWeek(DateTime starttimes, int days) {
            try {
                return _booking.GetBookingsWeek(starttimes, days);
            } catch(Exception ex) {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// Get the suggestions from a booking
        /// on a specific day
        /// </summary>
        /// <param name="booking">The booking to get the suggestions from</param>
        /// <param name="day">The day to get the suggestions from</param>
        /// <returns>The suggestions</returns>
        /*public List<BeBooking> GetSuggestions(BeBooking booking, DateTime day) {
            try {
                return _booking.GetSuggestions(booking, day);
            } catch(Exception ex) {
                throw new Exception(ex.Message);
            }
        }*/

        /// <summary>
        /// Save a booking
        /// </summary>
        /// <param name="booking">The booking to save</param>
        /// <returns>A message</returns>
        public string SaveBooking(BeBooking booking) {
            try {
                return _booking.SaveBooking(booking);
            } catch(Exception ex) {
                return ex.Message;
            }
        }

        /// <summary>
        /// Edit a booking
        /// </summary>
        /// <param name="booking">The booking to edit</param>
        /// <returns>A message</returns>
        public string EditBooking(BeBooking booking) {
            try {
                return _booking.EditBooking(booking);
            } catch(Exception ex) {
                return ex.Message;
            }
        }

        /// <summary>
        /// Delete a booking
        /// </summary>
        /// <param name="booking">The booking to delete</param>
        /// <param name="role">The role of the user</param>
        /// <returns>A message</returns>
        public string DeleteBooking(BeBooking booking, string role) {
            try {
                return _booking.DeleteBooking(booking, role);
            } catch(Exception ex) {
                return ex.Message;
            }
        }
    }
}